package dcpb.re.encrypt;

import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import java.util.AbstractMap.SimpleEntry;
import java.util.LinkedList;

import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.plaf.jpbc.field.curve.CurveElement;

public class Bob {
	private PubParams p;
	ProxyReEncrypt  d=new ProxyReEncrypt ();
	int t;	
	byte[] c1;
	Element c21;
	CurveElement c3;

	 
	 Element id,sk1,sk2;
	 byte[] encryptedMessage;
	public Bob(PubParams p,int t,List key) {
		this.p=p;
		this.t=t;
		id=(Element) key.get(0);
		sk1=(Element) key.get(1);
		sk2=(Element) key.get(2);
	}
	public void getRekey(Map c,Element c3) {
		this.c1=(byte[]) c.get("c1");
		this.c21=(Element) c.get("c21");
		this.c3=(CurveElement) c3;//d.recover(p,xs, ys, t);
	}
	public void getEncryptedMessage(byte[] encryptedMessage){

		this.encryptedMessage=encryptedMessage;//d.readFile("./data/encryptedMessage");

	}
	public void dec(Element A) {
		
		CurveElement  sk_r=(CurveElement) sk2.duplicate().mulZn(p.one.duplicate().div(A));
		//Element rt=aggre(id,sk2,Demo.revoke,Demo.P);
		Element ex=c3.getX();
		Element ey=c3.getY();
		CurveElement ae= (CurveElement) p.G1.newZeroElement();
		ae.setX(ex);
		ae.setY(ey);
		byte[] m2=d.Dec2(p,t,c1,c21,new SimpleEntry<>(sk1,sk2),sk_r,ae);
//	   try {
//		  String message=new String(AES.decrypt(encryptedMessage, new BigInteger(m2).toByteArray()));
//		  // System.out.println(message);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
	}
	Element aggre(Element xi,Element B,List<Element> x,List<Element> P) {
		Element temp=B;
		//System.out.println(x.size());
		for(int j=0;j<P.size();j++) {
			if(xi==x.get(j)) return null;
			temp=p.h.duplicate().mulZn(p.one.duplicate().div(P.get(j))).sub(temp).mulZn(p.one.duplicate().div(xi.duplicate().sub(x.get(j))));
		}
		return temp;
	}
	

}
